package org.dxy.middleware.dynamic.thread.pool.type;

/**
 * @ description:
 * @ author: dxy
 * @ createTime: 2025/10/4 11:25
 */
public final class Constants {

    private Constants() {
        // 禁止实例化
    }

    /** 线程池配置 Redis key 前缀：thread_pool_config:{appName}:{poolName} */

    private static final String THREAD_POOL_CONFIG_KEY_PATTERN  = "thread_pool_config:%s:%s";

    /** 线程池配置 Redis GLOB 模糊匹配：thread_pool_config:*:* */
    public static final String THREAD_POOL_CONFIG_KEY_GLOB = "thread_pool_config:*:*";

    /** 线程池运行时 Redis key 模板：thread_pool_runtime:{appName}:{poolName} */
    public static final String THREAD_POOL_RUNTIME_KEY_PATTERN = "thread_pool_runtime:%s:%s";

    /** 线程池运行时 Redis key 通配符（模糊匹配）示例：thread_pool_runtime:*:* */
    public static final String THREAD_POOL_RUNTIME_KEY_GLOB = "thread_pool_runtime:*:*";
    /**
     * 获取线程池配置 Redis key
     * @param appName 应用名称
     * @param poolName 线程池名称
     * @return 完整 Redis key
     */
    public static String configKey(String appName, String poolName) {
        return format(THREAD_POOL_CONFIG_KEY_PATTERN, appName, poolName);
    }

    /**
     * 获取线程池运行时 Redis key
     * @param appName 应用名称
     * @param poolName 线程池名称
     * @return 完整 Redis key
     */
    public static String runtimeKey(String appName, String poolName) {
        return format(THREAD_POOL_RUNTIME_KEY_PATTERN, appName, poolName);
    }


    private static String format(String pattern, String appName, String poolName) {
        if (appName == null || poolName == null) {
            throw new IllegalArgumentException("appName 和 poolName 不能为空");
        }
        return String.format(pattern, appName, poolName);
    }
}
